home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wdj0697.zip / SHMIDT.ZIP / VW32TEST.C < prev    next >
C/C++ Source or Header  |  1996-11-14  |  4KB  |  149 lines

  1. #define WIN32_LEAN_AND_MEAN
  2.  
  3. #include <windows.h>
  4. #include <tlhelp32.h>
  5. #include <stdio.h>
  6. #include <conio.h>
  7.  
  8. /* GetProcAddress semi-automation */
  9. #define GETPROC(proc,functype,hmodule) \
  10.             p##proc = (functype)GetProcAddress ((hmodule), #proc)
  11.             
  12. /* toolhelp32 functions */
  13. typedef HANDLE (WINAPI *TH32SNAPSHOT)(DWORD,DWORD);
  14. typedef BOOL (WINAPI *PROCESSWALK)(HANDLE,LPPROCESSENTRY32);
  15.  
  16. /* VxDCall alias from VCALL.DLL */
  17. DWORD WINAPI VCall (DWORD);
  18.  
  19. /* VW32DEMO Device IO Control subfunctions */
  20. typedef enum {
  21.    VW32DEMO_HITCOUNT = 1,
  22.    VW32DEMO_RMDIR
  23. }VW32DEMO_IOCTL;
  24.  
  25. HANDLE hVxD;   
  26. /* VxD name for Device IOCTL */
  27. static char *devname = "\\\\.\\VW32DEMO.VXD";
  28.  
  29. void Usage (void)
  30. {
  31.    fputs ("\nusage: 'VW32TEST -1' - Dump Hit Count",stderr);
  32.    fputs ("\n       'VW32TEST -2' - Reject RmDir",stderr);
  33.    fputs ("\n       'VW32TEST -3' - Process View\n",stderr);
  34. }
  35.  
  36. void CountWin32ServiceHits (void)
  37. {
  38. DWORD in[3] = {0};
  39.  
  40.    fputs ("\nCollecting Hit Counts",stderr);
  41.    fputs ("\nHit any key when get tired ...\n",stderr);
  42.    /* wait until key is pressed */
  43.    while (!kbhit ());
  44.  
  45.    puts ("\nService \tHit Count\n");
  46.    do
  47.    {
  48.       DeviceIoControl (hVxD,
  49.                        VW32DEMO_HITCOUNT,
  50.                        in, sizeof(in),
  51.                        NULL, 0,
  52.                        NULL,NULL);
  53.       printf ("%08lX\t%ld\n", in[1], in[2]);
  54.    }
  55.    while(in[0]);
  56. }
  57.  
  58. void PreventDeleteDirectory (void)
  59. {
  60.    DeviceIoControl (hVxD,VW32DEMO_RMDIR,NULL,0,NULL,0,NULL,NULL);
  61.    /* wait until key is pressed */
  62.    /* No Win32 app is able to delete any directory, */
  63.    /* while this loop is running */
  64.    fputs ("\nTry to remove empty directory from Explorer",stderr);
  65.    fputs ("\nHit any key when get annoyed ...",stderr);
  66.    while (!kbhit ());
  67.    /* remove Int21 service hook */
  68.    DeviceIoControl (hVxD,VW32DEMO_RMDIR,NULL,0,NULL,0,NULL,NULL);
  69. }
  70.  
  71. void UnobfuscatedProcessView (void)
  72. {
  73. DWORD obfuscator;
  74. HANDLE hProcSnap;
  75. HMODULE k32;
  76. TH32SNAPSHOT pCreateToolhelp32Snapshot;
  77. PROCESSWALK  pProcess32First, pProcess32Next;
  78. PROCESSENTRY32 pe;
  79. BOOL result;
  80.  
  81.    obfuscator = VCall (0x00000000, GetCurrentProcessId ());
  82.    printf ("\nWin32 Process ID Obfuscator = %08lX\n", obfuscator);
  83.       
  84.    k32 = GetModuleHandle ("KERNEL32");
  85.    GETPROC(CreateToolhelp32Snapshot,TH32SNAPSHOT,k32);
  86.    GETPROC(Process32First,PROCESSWALK,k32);
  87.    GETPROC(Process32Next,PROCESSWALK,k32);
  88.  
  89.    if (pCreateToolhelp32Snapshot && 
  90.        pProcess32First && 
  91.        pProcess32Next)
  92.       if (hProcSnap = (pCreateToolhelp32Snapshot) 
  93.                            (TH32CS_SNAPPROCESS,0))
  94.       {
  95.          puts ("\nEncoded PID  Decoded PID  Filename\n");
  96.          pe.dwSize = sizeof(pe);
  97.          for (result = pProcess32First(hProcSnap, &pe); 
  98.               result; 
  99.               result = pProcess32Next(hProcSnap, &pe))
  100.             printf ("%-13lX%-13lX%s\n", 
  101.                     pe.th32ProcessID, 
  102.                     pe.th32ProcessID ^ obfuscator, 
  103.                     pe.szExeFile);
  104.             
  105.          CloseHandle (hProcSnap);
  106.       }           
  107. }
  108.  
  109. int main(int argc, char *argv[])
  110. {
  111.    if (argc < 2 || '-' != argv[1][0])
  112.    {
  113.       Usage ();
  114.       return (1);
  115.    }
  116.    
  117.    hVxD = CreateFile(devname,0,0,NULL,0,
  118.                      FILE_FLAG_DELETE_ON_CLOSE,NULL);
  119.                     
  120.    if (INVALID_HANDLE_VALUE == hVxD)
  121.    {
  122.       // Footprnt is not installed
  123.       fputs ("\nUnable to locate VW32DEMO.VXD",stderr);
  124.       return (1);      
  125.    }                       
  126.  
  127.    switch (argv[1][1])
  128.    {
  129.       case '1':
  130.          CountWin32ServiceHits ();
  131.          break;
  132.  
  133.       case '2':
  134.          PreventDeleteDirectory ();
  135.          break;
  136.  
  137.       case '3':
  138.          UnobfuscatedProcessView ();
  139.          break;
  140.  
  141.       default:
  142.          Usage ();
  143.          break;
  144.    }
  145.  
  146.    CloseHandle (hVxD);
  147.    return (0);
  148. }
  149.